<?php include('./templete/public/head.php') ?>
<body>
<!--评估-->
<div class="assess-main">
    <div class="assess-content ">
        <form class="myform">
            <div class="c-top">
                <ul class="comm-table-view">

                    <li class="table-view-cell table-view-cell2">
                        <a>
                            <span>理由</span>
                            <div class="top-text text2">
                                <textarea name="content"></textarea>
                            </div>
                        </a>
                    </li>
                    <li class="table-view-cell">
                        <a>
                            <span class="title">实施改善（部门）</span>
                            <span class="line">|</span>
                            <span class="input" id="showDepartPicker">
                                        <input type="text" name="department" id="departName" value="<?php echo $rows['department']?>" placeholder="" readonly/></span>
                            <input type="hidden" name="departid" id="departid" value="<?php echo $rows['departid']?>" placeholder="" readonly/></span>
                            <span class="fr"><i class="iconfont icon-youjiantou"></i></span>
                        </a>
                    </li>
                </ul>
            </div>
            <hr class="bgcolor"/>
            <input type="hidden" name="id" value="<?php echo $rows['id'] ?>">
        </form>
        <div class="comm-btn assess-btn">
            <span class="color1 " onclick="deal()">通过</span>
            <span class="color2 " onclick="deny()">不实施</span>
        </div>
    </div>
</div>
<script src="_js/plug/mui.picker.all.js"></script>
<?php include('./templete/public/script.php') ?>
</body>

<script>

    $('#showDepartPicker').on('click', function () {
        select_entercontact('single', 'department', [], 'department');
    });

    function select_entercontact(mode, type, _partners_id, cases) {
        wx.invoke("selectEnterpriseContact", {
                "fromDepartmentId": -1,// 必填，表示打开的通讯录从指定的部门开始展示，-1表示自己所在部门开始, 0表示从最上层开始
                "mode": mode,// 必填，选择模式，single表示单选，multi表示多选
                "type": [type],// 必填，选择限制类型，指定department、user中的一个或者多个
                //"selectedDepartmentIds": ["2","3"],// 非必填，已选部门ID列表。用于多次选人时可重入，single模式下请勿填入多个id
                "selectedUserIds": _partners_id// 非必填，已选用户ID列表。用于多次选人时可重入，single模式下请勿填入多个id
            }, function (res) {
                if (res.err_msg == "selectEnterpriseContact:ok") {
                    if (typeof res.result == 'string') {
                        res.result = JSON.parse(res.result) //由于目前各个终端尚未完全兼容，需要开发者额外判断result类型以保证在各个终端的兼容性
                    }
                    var selectedUserList = res.result.userList; // 已选的成员列表
                    var userId = Array();
                    var userName = Array();
                    var userAvatar = Array();
                    var departmentId = Array();
                    var departemntName = Array();
                    var selectedDepartmentList = res.result.departmentList;// 已选的部门列表
                    for (var i = 0; i < selectedDepartmentList.length; i++) {
                        var department = selectedDepartmentList[i];
                        departmentId[i] = department.id;// 已选的单个部门ID
                        departemntName[i] = department.name;// 已选的单个部门名称
                    }
                    for (var i = 0; i < selectedUserList.length; i++) {
                        var user = selectedUserList[i];
                        userId[i] = user.id; // 已选的单个成员ID
                        userName[i] = user.name;// 已选的单个成员名称
                        userAvatar[i] = user.avatar;// 已选的单个成员头像
                    }
                    if (cases == 'user') {
                        $("#hezuoPeople").val(userName);
                        $("#partners_id").val(userId);
                    }
                    if (cases == 'department') {
                        $('#departName').val(departemntName);
                        $('#departid').val(departmentId);
                    }
                }
            }
        );
    }

    function deny() {
        layer.confirm('确认不实施提议吗？', {
            btn: ['确认', '取消']
        }, function () {
            let load = layer.load();
            param = $('.myform').serializeArray();
            $.ajax({
                    url: "<?php echo url('deny')?>",
                    type: 'post',
                    data: param,
                    success: function (data) {
                        layer.close(load);
                        layer.msg(data.msg);
                        if (data.code == 1) {
                            setInterval(function () {
                                location.href = "<?php echo url('detail', ['id' => $rows['id']])?>"
                            }, 2000)
                        }
                    }
                }
            )
        }, function () {
            layer.msg('操作已取消');
        })
    }
    function deal() {
        layer.confirm('确认通过提议吗？', {
            btn: ['确认', '取消']
        }, function () {
            let load = layer.load();
            param = $('.myform').serializeArray();
            $.ajax({
                    url: "<?php echo url('choose')?>",
                    type: 'post',
                    data: param,
                    success: function (data) {
                        layer.close(load);
                        layer.msg(data.msg);
                        if (data.code == 1) {
                            setInterval(function () {
                                location.href = "<?php echo url('detail', ['id' => $rows['id']])?>"
                            }, 2000)
                        }
                    }
                }
            )
        }, function () {
            layer.msg('操作已取消');
        })
    }
</script>
</html>